<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateHouseFieldTypeCategoryTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function up()
    {
      $table = $this->table('house_field_type_categories');
      $table->setId('id')
            ->setEngine('InnoDB')
            ->addColumn('name', 'string', ['comment' => '参数类型'])
            ->create();

      // 默认数据
      $default = [
        ['id' => 1, 'name' => '户型'],
        ['id' => 2, 'name' => '装修类型'],
        ['id' => 3, 'name' => '用途'],
        ['id' => 4, 'name' => '朝向'],
        ['id' => 5, 'name' => '楼层类型'],
        ['id' => 6, 'name' => '税务承担'],
        ['id' => 7, 'name' => '区域'],
      ];

      foreach ($default as $key => $value) {
        $table->insert($value);
      }
      $table->saveData();
    }

    public function down() {
      $this->dropTable("house_field_type_categories");
    }
}
